<?php

require_once dirname(__FILE__).'/../lib/plan_radaGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/plan_radaGeneratorHelper.class.php';

/**
 * plan_rada actions.
 *
 * @package    dnevnik
 * @subpackage plan_rada
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class plan_radaActions extends autoPlan_radaActions
{
   public function executeUnos(sfWebRequest $request)
   {
      $skolas = DbFinder::from('Skola')->select(array('Id', 'Ime'))->find();
      $predmets = DbFinder::from('Predmet')->select(array('Id', 'PredmetNaziv'))->find();

      $this->skolas = array();
      foreach($skolas as $skola)
        $this->skolas[$skola['Id']] = $skola['Ime'];
      $this->predmets = array();
      foreach($predmets as $predmet)
        $this->predmets[$predmet['Id']] = $predmet['PredmetNaziv'];
   }

   public function executeUnosUnos(sfWebRequest $request)
   {
      $red_br = DbFinder::from('PlanRada')->where('SkolaId', $request->getParameter('skola_id'))->where('PredmetId', $request->getParameter('predmet_id'))->where('Razred', $request->getParameter('razred'));
      if($profesor_id = $request->getParameter('profesor_id'))
        $red_br = $red_br->where('ProfesorId', $profesor_id);
      $red_br = $red_br->count() + 1;

      $opis = Functions::cirLat(trim($request->getParameter('opis')));

      $plan_rada = new PlanRada();
      $plan_rada->setOpis($opis);
      $plan_rada->setPredmetId($request->getParameter('predmet_id'));
      $plan_rada->setSkolaId($request->getParameter('skola_id'));
      $plan_rada->setRazred($request->getParameter('razred'));
      $plan_rada->setRedBr($red_br);
      if($profesor_id)
        $plan_rada->setProfesorId($profesor_id);

      $plan_rada->save();

      return $this->renderText(($red_br).' - '.$opis);
   }

}
